package com.atguigu.vod.controller;

/**
 * @author cyt
 * @create 2020-06-01 10:37
 */

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.atguigu.commonutils.R;
import com.atguigu.vod.utils.AliyunVodSDKUtils;
import com.atguigu.vod.utils.Contast;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Slf4j
@Api(description = "阿里云视频点播微服务")
@RestController
@RequestMapping("/eduvod/video")
public class VideoController {
    @GetMapping("getplayauth/{videoId}")
    public R getVideoPlayAuth(@PathVariable("videoId") String videoId) throws Exception {
        //获取阿里云存储相关常量
        String accessKeyId = "LTAI4FgWhqpqYUTuHH48BDAB";
        String accessKeySecret = "1wYL4DVgzmb1z8mjXhClQ9luAxZvVq";
        //初始化
        System.out.println("->" + Contast.accessKey_Secret);
        System.out.println("->" + Contast.accessKey_Id);
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);
        //请求
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId);
        //响应
        GetVideoPlayAuthResponse response = client.getAcsResponse(request);
        //得到播放凭证
        String playAuth = response.getPlayAuth();
        //返回结果
        System.out.println(playAuth);

        log.info("success");
        return R.ok().message("获取凭证成功").data("playAuth", playAuth);
    }
}